<template>
	<view class="main">
		<view class="row-item v-box">
			<view class="row-ts dis-row">
				<view class="rs-name">绑定手机号</view>
				<view class="rs-pos">
					<input type="text" v-model="sendform.phone" placeholder="请输入手机号"/>
				</view>
			</view>
			<view class="row-ts dis-row">
				<view class="rs-name">验证码</view>
				<view class="rs-pos poser">
					<input type="text" class="sends" v-model="sendform.code" placeholder="请输入验证码"/>
					<view class="sendcode" >
						<text v-if="sendDataShow == true" @click="getCode">{{codemsg}}</text>
						<text v-if="sendDataShow == false">{{sendData}}秒后获取</text>
					</view>
				</view>
			</view>
			<view style="height: 120rpx;"></view>
           <view class="queding">
			   <button class="brn" @click="sendPost">确定</button>
		   </view>
			
		</view>
	</view>
</template>

<script>
// import pop from "@/components/ming-pop/ming-map.vue"
import Index from '@/common/index-model.js'
let index=new Index();
let that = null;	
export default {
	data() {
		return {
			addresstemp:{},
			sendform:{
				phone:'',
				code:''
			},
			codemsg:'发送验证码',
			sendDataShow: true,
			sendData: 60,
			phonecheckmsg:'',
			isphone:true,
			iscode:true,
			codecheckmsg:'',
			wanshanData:{},
			type:''
		}
	},
	// components: {
	// 	pop
	// },
	onLoad(opt) {
        this.wanshanData = JSON.parse(opt.str)
		this.type=opt.type
	},
	methods:{
		sendPost() {
			if(this.sendform.phone == '' || this.sendform.code == ''){
				index.show_tips('请认真填写手机号')
				return false
			}
			index.getPublicUserMember({"mobile":this.sendform.phone,"code":this.sendform.code},'client/individual/changesPhone','post',res=>{
				if(res.data.code == 200 && res.data.result.status==1){
					//this.wanshanData.tel = this.sendform.phone
					let url=''
					if(this.type == 'add'){
						this.wanshanData.tel =this.sendform.phone
						 url = "./index?str="+JSON.stringify(this.wanshanData)
						index.redirectto(url)
					}else{
						this.wanshanData.tel =this.sendform.phone
						this.wanshanData.form.tel =this.sendform.phone
						this.wanshanData.form.mobile =this.sendform.phone
					    url = "./editprefect?str="+JSON.stringify(this.wanshanData)
						index.redirectto(url)
					}
					
				}else{
					index.show_tips(res.data.message)
					return false
				}
			})
		},
        getCode() {
			let sendCode = {
				"mobile":this.sendform.phone,
				"smsmode":0
			}
			if(sendCode.mobile == ''){
				index.show_tips('请先输入电话号码')
				return false
			}
			index.getPublicMember(sendCode,'sys/clientSms','post',res=>{
				if(res.data.success){
					this.sendDataShow = this.sendDataShow==true?false:true;
					var sen = setInterval(()=>{
						if(this.sendData <= 0){
							this.sendData = 60
							this.sendDataShow = true
							clearInterval(sen)
						}
						this.sendData--
					},1000)
				}else{
					this.sendDataShow = true
					this.sendData = 60
					index.show_tips(res.data.message)
					return false
				}
			})
				
		}
	}
}
</script>

<style>
@import url("@/static/css/publics.css");
@import url("./editphone.css");	
</style>